package com.lj.ljminsu.merchant.GuanjiaController;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.lj.ljminsu.merchant.GuanjiaBean.ChekiIdSaveUtil;
import com.lj.ljminsu.merchant.GuanjiaBean.TjUzRole;
import com.lj.ljminsu.merchant.GuanjiaBean.UzRoleBean;
import com.lj.ljminsu.merchant.GuanjiaService.IoPinjService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@CrossOrigin
public class SaveController {
    @Resource
    private IoPinjService ioPinjService;
    @RequestMapping("sava")
    @ResponseBody
    public Integer SendSms(TjUzRole tjUzRole) {
//        获取当前用户id，如前台无法取到在后台取再set
        int max=1000,min=1;
        int ran2 = (int) (Math.random()*(max-min)+min);
        tjUzRole.setzId(ran2);
        Integer state= null;
        try {
            state = ioPinjService.SaveUz(tjUzRole);
            Integer m=666666;
//                    发送邀请短信 打开可用
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAIZaadS5qxHbmw", "YEtdvO851joz5Ro5B1VDEVDtNpAigc");
            IAcsClient client = new DefaultAcsClient(profile);
            CommonRequest request = new CommonRequest();
            request.setMethod(MethodType.POST);
            request.setDomain("dysmsapi.aliyuncs.com");
            request.setVersion("2017-05-25");
            request.setAction("SendSms");
            request.putQueryParameter("RegionId", "cn-hangzhou");
            request.putQueryParameter("PhoneNumbers", "17607520261");
            request.putQueryParameter("SignName", "wangyeTujia");
            request.putQueryParameter("TemplateCode", "SMS_172010198");
            request.putQueryParameter("TemplateParam",  "{\"code\":"+m+"}");
        try {
                CommonResponse response = client.getCommonResponse(request);
                System.out.println(response.getData());
            } catch (Exception e) {
            e.printStackTrace();
        }
        } catch (Exception e) {
            state=0;
        }
        return state;
    }

    @RequestMapping("uzRole")
    @ResponseBody
    public List<UzRoleBean> FindUzrole(Integer userId){
        Integer userId2=1;
        List<UzRoleBean> roleBeanList = ioPinjService.findUzRole(userId2);
        return roleBeanList;
    }
    @RequestMapping("Cheks")
    @ResponseBody
    public String SaveCheks(ChekiIdSaveUtil chekiIdSaveUtil){
        String[] split = chekiIdSaveUtil.getChekIds().split("#");
            for (String cid:split){
              chekiIdSaveUtil.setChildModuleId(cid);
                ioPinjService.SaveCheksDao(chekiIdSaveUtil);
            }
//        List<ChekiIdSaveUtil>  list = ioPinjService.findRoleC(chekiIdSaveUtil);

        Integer userId2=1;

            return null;

    }
    @RequestMapping("Cheks2")
    @ResponseBody
    public List<ChekiIdSaveUtil> SaveCheks(Integer uId){
        ChekiIdSaveUtil chekiIdSaveUtil=new ChekiIdSaveUtil();
        chekiIdSaveUtil.setuId(uId);
        List<ChekiIdSaveUtil>  list = ioPinjService.findRoleC(chekiIdSaveUtil);
        Integer userId2=1;
        return list;

    }

}
